package com.szrt.day20170424.ch03;


import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.Reader;
import java.io.Writer;

import org.junit.Test;

public class AskTest {
	
	@Test
	public void testName() throws Exception {
		
		String age="100";
		
		File file  = new File("io1704/ask.txt");
		Reader  reader  = new FileReader(file);
		BufferedReader   br= new BufferedReader(reader);
		
		File outFile  = new File("io1704/answer.txt");
		Writer writer = new FileWriter(outFile);
		BufferedWriter  bw  = new  BufferedWriter(writer);
		
		String string = "";
		while((string = br.readLine()) != null){
			
			string =string.substring(0, string.length()-1);
			
			if(string.contains("*")){
				System.out.println(string);
				
				String[] as = string.split("\\*");
				
				int num1= Integer.parseInt(as[0]);
				int num2= Integer.parseInt(as[1]);
				int jieguo = cheng(num1, num2);
				
				System.out.println(jieguo);
				
				bw.write(string+"="+jieguo);
				bw.newLine();
				
				
			}else if(string.contains("+")){
				System.out.println(string);
				
				String[] as = string.split("\\+");
				
				int num1= Integer.parseInt(as[0]);
				int num2= Integer.parseInt(as[1]);
				int jieguo = add(num1, num2);
				
				System.out.println(jieguo);
				
				bw.write(string+"="+jieguo);
				bw.newLine();
				
				
			}
		}
		
		bw.flush();
		
		
		
	}
	
	
	public int add(int a ,int b){
		return a+b;
	}
	public int cheng(int a ,int b){
		return a*b;
	}

}
